<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>编辑学生</title>
    <style>
        .form-container {
            width: 500px;
            margin: 50px auto;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 5px;
            background-color: #fff;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-group label {
            display: block;
            margin-bottom: 5px;
            color: #333;
        }
        .form-group input, .form-group select {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        .button-group {
            display: flex;
            gap: 10px;
            margin-top: 20px;
        }
        .button-group button {
            flex: 1;
            padding: 10px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        .submit-btn {
            background-color: #4CAF50;
            color: white;
        }
        .cancel-btn {
            background-color: #f44336;
            color: white;
        }
        h2 {
            text-align: center;
            color: #333;
            margin-bottom: 20px;
        }
    </style>
</head>
<body>
    <%
        // 获取URL中的学生ID参数
        String studentId = request.getParameter("id");
        // 如果URL中没有id参数，尝试从request attribute中获取
        if (studentId == null || studentId.isEmpty()) {
            studentId = request.getAttribute("studentId") != null ? 
                       (String)request.getAttribute("studentId") : "";
        }
    %>
    <div class="form-container">
        <h2>编辑学生</h2>
        <form action="student" method="post">
            <input type="hidden" name="action" value="update">
            <input type="hidden" name="studentId" value="<%=studentId%>">
            
            <div class="form-group">
                <label>学号：</label>
                <input type="text" value="<%=studentId%>" disabled>
            </div>
            
            <div class="form-group">
                <label>姓名：</label>
                <input type="text" name="name" value="${student.name}" required>
            </div>
            
            <div class="form-group">
                <label>性别：</label>
                <select name="gender">
                    <option value="男" ${student.gender == '男' ? 'selected' : ''}>男</option>
                    <option value="女" ${student.gender == '女' ? 'selected' : ''}>女</option>
                </select>
            </div>
            
            <div class="form-group">
                <label>班级：</label>
                <input type="text" name="className" value="${student.className}" required>
            </div>
            
            <div class="form-group">
                <label>数据库成绩：</label>
                <input type="number" name="database" value="${student.scores['数据库']}" 
                       min="0" max="100" step="0.1" required>
            </div>
            
            <div class="form-group">
                <label>linux操作系统成绩：</label>
                <input type="number" name="os" value="${student.scores['操作系统']}" 
                       min="0" max="100" step="0.1" required>
            </div>
            
            <div class="form-group">
                <label>Java程序设计成绩：</label>
                <input type="number" name="java" value="${student.scores['Java程序设计']}" 
                       min="0" max="100" step="0.1" required>
            </div>
            
            <div class="button-group">
                <button type="submit" class="submit-btn">保存</button>
                <button type="button" onclick="history.back()" class="cancel-btn">返回</button>
            </div>
        </form>
    </div>
</body>
</html>